package com.android.mall.adapter;

import java.util.List;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.android.mall.activity.R;
import com.android.mall.data.CReport;

public class ReportListAdapter extends ArrayAdapter<CReport>{

//	private ListView listView;
	
	public ReportListAdapter(Activity activity, List<CReport> reportList, ListView listView){
		super(activity, 0, reportList);
		
//		this.listView = listView;
	}
	
	public  View getView(int position, View convertView, ViewGroup parent){
		
		Activity activity = (Activity)getContext();
		
		//Inflate the views form XML
		View rowView = convertView;
		ReportViewCache reportViewCache;
		if (rowView == null){
			LayoutInflater inflater = activity.getLayoutInflater();
			rowView = inflater.inflate(R.layout.home_report_item, null);
			reportViewCache = new ReportViewCache(rowView);
			rowView.setTag(reportViewCache);
		}else{
			reportViewCache = (ReportViewCache)rowView.getTag();
		}
		CReport report = getItem(position);
		
		//Load the title and set it on the TextView
		String title = report.getTitle();
		TextView textView = reportViewCache.getTextView();
		textView.setText(title);
		
		return rowView;
	}

}
